package com.serialcommunication.controller;

import java.util.ArrayList;
import java.util.BitSet;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.List;

import org.apache.soap.encoding.Hex;

import com.serialcommunication.communication.Reader;
import com.serialcommunication.communication.Writer;
import com.serialcommunication.constants.ProtocolConstants;
import com.serialcommunication.helper.MessageFactory;

import gnu.io.CommPort;
import gnu.io.CommPortIdentifier;
import gnu.io.NoSuchPortException;
import gnu.io.PortInUseException;

//import javax.comm.*;

public class _Tests {

	/**
	 * @param args
	 * @throws javax.comm.NoSuchPortException
	 * @throws Exception
	 */
	public static void main(String[] args) throws Exception {
//		Action.X_TARGET
//		
//	
	}

	public static Hex bytesToHex(byte[] bytes) {
		final char[] hexArray = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
		char[] hexChars = new char[bytes.length * 2];
		int v;
		for (int j = 0; j < bytes.length; j++) {
			v = bytes[j] & 0xFF;
			hexChars[j * 2] = hexArray[v >>> 4];
			hexChars[j * 2 + 1] = hexArray[v & 0x0F];
		}
		return new Hex(new String(hexChars));
	}

	public static BitSet fromByte(byte b, String sign) {
		BitSet bits = new BitSet(8);
		for (int i = 0; i < 8; i++) {
			if (i == 7) {
				if (sign.contains("-")) {
					bits.set(i, true);
				} else if (sign.contains("+")) {
					bits.set(i, false);
				} else {
					bits.set(i, (b & 1) == 1);
					b >>= 1;
				}
			} else {
				bits.set(i, (b & 1) == 1);
				b >>= 1;
			}
		}

		return bits;
	}

	public static int[] toIntArray(BitSet set) {
		int[] result = new int[8];
		for (int i = 0; i < 8; i++) {
			if (set.get(i))
				result[i] = 1;
			else
				result[i] = 0;
		}
		return result;
	}


}
